home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 January / macformat-033.iso / mac / Shareware City / Developers / VideoToolbox / VideoToolboxSources / AfterDark.c next >
Encoding:
C/C++ Source or Header  |  1995-06-23  |  3.3 KB  |  114 lines  |  [TEXT/CWIE]

  1. /* AfterDark.c
  2.  
  3. error=AfterDarkDisable();
  4. error=AfterDarkEnable();
  5.  
  6. Disable and later re-enable the popular screen saver, AfterDark. An error code is
  7. returned if the relevant Gestalt selectors are not installed, i.e. no
  8. AfterDark-compatible screen saver is present.
  9.  
  10. Written by David Brainard, based on documentation supplied by Berkeley Systems
  11. Mac Tech Support, brklysystm@aol.com. Ask them for the AfterDarkGestalt.h file.
  12.  
  13. The interface to the screen saver is generic. Any screen saver that installs the
  14. same Gestalt selectors would be controlled by these two routines, but we haven't
  15. tested that.
  16.  
  17. SEE ALSO:
  18. IsFileSharingOn.c
  19.  
  20. HISTORY:
  21. 6/15/95    dhb        Wrote it.
  22. 6/16/95    dhb        Don't call procedure on PPC, as it causes a crash.    
  23. 6/20/95    dhb        Make it work on PPC, use symbol GENERATING68K.
  24. 6/21/95    dhb        Conditional compiles so that it will still work on 68K.
  25. 6/23/95 dgp        Removed the stuff that was MATLAB-specific. Renamed
  26.                             variables to make the code more self documenting.
  27. 6/23/95    dhb        Added necessary stuff from AfterDarkGestalt.h.
  28.                             Include VideoToolbox.h.
  29.                             Move prototypes to VideoToolbox.h.
  30. */
  31.  
  32. #include <VideoToolbox.h>
  33.  
  34. // Gestalt called with 'SAVR' selector returns longword bitmask.
  35. #define gestaltScreenSaverAttr 'SAVR'
  36. enum {
  37.     gestaltSaverTurnedOn = 0,                        /* saver enabled/disabled. */
  38.     gestaltSaverAsleep,                                    /* saver currently asleep. */
  39.     gestaltSaverDemoMode,                                /* saver sleeping in demo mode. */
  40.     gestaltSaverPasswordMode,                        /* saver sleeping in password-protected mode. */
  41.     gestaltAppDrawingDisabled                        /* Quickdraw drawing disallowed between module animation frames. */
  42. };
  43.  
  44. // Gestalt called with 'SAVC' selector returns a pointer
  45. // to a procedure.  Pass the appropriate command
  46. #define gestaltScreenSaverControl 'SAVC'
  47. enum SaverCommand {
  48.     gestaltSaverWakeUp,
  49.     gestaltSaverSleep,
  50.     
  51.     /* defined in AD 2.0x and later */
  52.     gestaltSaverOn,
  53.     gestaltSaverOff,
  54.     
  55.     /* defined for AD 3.0 and later */
  56.     gestaltSysIQOn,
  57.     gestaltSysIQOff,
  58.     
  59.     gestaltForceShort = 257
  60. };
  61. typedef short SaverCommand;
  62. typedef pascal OSErr (*SaverControlProcPtr) (SaverCommand command);
  63.  
  64. static OSErr AfterDarkCommand(SaverCommand command);
  65.  
  66. #if !GENERATING68K
  67.     enum {
  68.         uppSaverProcInfo=kPascalStackBased
  69.              | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  70.              | STACK_ROUTINE_PARAMETER(1,SIZE_CODE(sizeof(SaverCommand)))
  71.     };
  72. #endif
  73.  
  74.  
  75. OSErr AfterDarkEnable(void)
  76. {
  77.     return AfterDarkCommand(gestaltSaverOn);    
  78. }
  79.  
  80.  
  81. OSErr AfterDarkDisable(void)
  82. {
  83.     return AfterDarkCommand(gestaltSaverOff);    
  84. }
  85.  
  86. static OSErr AfterDarkCommand(SaverCommand command)
  87. {
  88.     OSErr error;
  89.     long response;
  90.     SaverControlProcPtr saverProcPtr;
  91.     #if !GENERATING68K
  92.         UniversalProcPtr saverUPP=NULL;
  93.     #endif
  94.  
  95.     // Make sure the screen saver is installed, return if not.
  96.     error=Gestalt(gestaltScreenSaverAttr,&response);
  97.     if(error)return error;    
  98.     
  99.     // Get a pointer to the screen saver's control procedure
  100.     error=Gestalt(gestaltScreenSaverControl,(long *)&saverProcPtr);
  101.     if(error)return error;    
  102.     
  103.     // Ask the control procedure to perform the command
  104.     #if GENERATING68K
  105.         error=(*saverProcPtr)(command);
  106.     #else
  107.         saverUPP=NewRoutineDescriptor((ProcPtr)saverProcPtr,uppSaverProcInfo,kM68kISA);
  108.         if(saverUPP==NULL)return 1;    // Memory allocation failed.
  109.         error=(OSErr)CallUniversalProc(saverUPP,uppSaverProcInfo,command);
  110.         DisposeRoutineDescriptor(saverUPP);
  111.     #endif
  112.     return error;
  113. }
  114.